@extends('admin.base')
@section('title', '添加规格组合')
@section('content')
<div class="layui-card">
    <fieldset class="layui-elem-field">
        <div class="layui-field-box">
            <a class="layui-btn-sm" href="{{url('admin/home')}}">首页</a>&raquo;
            <a class="layui-btn-sm" href="{{url('admin/shop/index?page='.$request->page.'&keywords='.$request->keywords.'&label='.$request->label.'&type='.$request->type.'&brand='.$request->brand.'&state='.$request->state.'&sell='.$request->sell.'&title='.$request->title.'&sort='.$request->sort)}}">商品列表</a>&raquo;
            <a class="layui-btn-sm" href="{{url("admin/sku/index?id=".$shop_id.'&page='.$request->page.'&keywords='.$request->keywords.'&label='.$request->label.'&type='.$request->type.'&brand='.$request->brand.'&state='.$request->state.'&sell='.$request->sell.'&title='.$request->title.'&sort='.$request->sort)}}">{{$gname}} - 规格组合列表</a>&raquo;
            <a href="" class="layui-btn-sm">添加规格组合</a>
        </div>
    </fieldset>
    <div class="layui-card-body">
        <form class="layui-form layui-form-pane" method="post" action="{{url('admin/sku_add')}}" enctype="multipart/form-data" >
            <input type="hidden" name="shop_id" value="{{$shop_id}}">
            <input type="hidden" name="id" value="{{$id}}">
            @foreach($yxzlist as $yxzvo)
                <div class="layui-form-item" pane>
                    <label class="layui-form-label">{{$yxzvo->kname}}</label>
                    <div class="layui-input-inline" style="width: auto;">
                        @foreach($yxzvo->info as $valvo)
                            @if($valvo->is_xz == 1)
                                <input type="radio"  name="{{$loop->parent->iteration}}" value="{{$yxzvo->pivot->Kid}}-{{$valvo->id}}" title="{{$valvo->vname}}" lay-skin="primary" @if($loop->iteration == 1)  @endif>
{{--                                <input type="checkbox"  name="{{$loop->parent->iteration}}[]" value="{{$yxzvo->pivot->Kid}}-{{$valvo->id}}" title="{{$valvo->vname}}" lay-skin="primary" @if($loop->iteration == 1) checked @endif>--}}
                            @else

                            @endif
                        @endforeach
                    </div>
                </div>
            @endforeach
            {{--<div class="layui-form-item">--}}
                {{--<label class="layui-form-label">上传Logo</label>--}}
                {{--<div class="layui-input-inline" style="width:30%;">--}}
                    {{--<input type="radio" name="type" value="1"  lay-filter="type" title="否" checked="">--}}
                    {{--<input type="radio" name="type" value="2"  lay-filter="type" title="是">--}}
                {{--</div>--}}
                {{--<div class="layui-form-mid layui-word-aux"></div>--}}
            {{--</div>--}}
            <div class="layui-form-item" id="qrcode">
                <label class="layui-form-label">Logo</label>
                <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
                <input type="hidden" name="picname" id="picname">
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><i class="layui-icon layui-icon-rate-solid" style="font-size:8px;color:red;"></i>货源ID</label>
                <div class="layui-input-inline">
                    <input type="number" name="store_id" required  lay-verify="required" autocomplete="off" class="layui-input" value="" placeholder="请输入货源ID">
                </div>
            </div>

            {{--<div class="layui-form-item">--}}
                {{--<label class="layui-form-label"><i class="layui-icon layui-icon-rate-solid" style="font-size:8px;color:red;"></i>销售价</label>--}}
                {{--<div class="layui-input-inline">--}}
                    {{--<input type="number" name="sell_price" required  lay-verify="required" autocomplete="off" class="layui-input" value="0" placeholder="请输入销售价">--}}
                {{--</div>--}}
            {{--</div>--}}
            {{--<div class="layui-form-item" pane>--}}
                {{--<label class="layui-form-label"><i class="layui-icon layui-icon-rate-solid" style="font-size:8px;color:red;"></i>库存</label>--}}
                {{--<div class="layui-input-inline" style="width:300px;">--}}
                    {{--<input type="text" name="sum" required  lay-verify="required" placeholder="请输入库存" autocomplete="off" class="layui-input" value="">--}}
                {{--</div>--}}
                {{--<div class="layui-form-mid layui-word-aux"></div>--}}
            {{--</div>--}}
            {{--<div class="layui-form-item" pane>--}}
                {{--<label class="layui-form-label">销量</label>--}}
                {{--<div class="layui-input-inline" style="width:300px;">--}}
                    {{--<input type="text" name="sale_num" placeholder="请输入销量" autocomplete="off" class="layui-input" value="0">--}}
                {{--</div>--}}
                {{--<div class="layui-form-mid layui-word-aux"></div>--}}
            {{--</div>--}}
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit lay-filter="formDemo" type="button">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>
    </div>
</div>
@endsection

@section('js')
<script type="text/javascript">
    layui.use(['form', 'layedit',], function () {
        var form = layui.form, layedit = layui.layedit;
        layedit.set({
            //暴露layupload参数设置接口 --详细查看layupload参数说明
            uploadImage: {
                url: "{:url('Good/add_pic')}" //接口url
                    , type: 'post' //默认post
            },
            tool: [
                'html', 'code', 'strong', 'italic', 'underline', 'del','|', 'fontFomatt', 'colorpicker', 'face'
                , '|', 'left', 'center', 'right', '|', 'link',  'image_alt'
                
            ],
          height: '90%'
        });
        var index = layedit.build('demo', {height: 500,width:1000}); //建立编辑器
        layedit.getContent(index);
        form.render();
        form.verify({
            content: function () {
                return layedit.sync(index);
            }
        });
        //监听提交
        form.on('submit(formDemo)', function(data){
            // var aa = layedit.getContent(index);
            // data.field.contents = aa;
            var id = $("input[name=shop_id]").val();
            layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
                ajax("{{url('admin/sku/sku_add')}}",data.field,function(data){
                    layer.close();
                    layer.closeAll();
                    layer.msg(data.msg);
                    if(data.code == 1){
                        // location.href = '/admin/sku/index?id='+id;
                        location.href=location.href;
                    }
                });
            });
            return false;
        });

        //绑定单选
        form.on('radio(type)', function (data) {
            if(data.value == 1){
                $("#qrcode").css('display','none');
            }else{
                $("#qrcode").css('display','block');
            }
        });

        layui.use('upload',function(){
            var $ = layui.jquery
                ,upload = layui.upload;
            //指定允许上传的文件类型
            upload.render({
                elem: '#test3'
                ,url: '/admin/shop_up' //改成您自己的上传接口
                ,accept: 'file' //普通文件
                ,done: function(res){
                    layer.msg(res.msg);
                    if(res.code == 1){
                        $("#test3").text('上传成功!');
                        $("#picname").val(res.info);
                    }
                }
            });
        });
    });

</script>
@endsection
